package com.boot.system.controller;

import com.boot.common.anno.AnnoLog;
import com.boot.common.anno.RepeatSubmit;
import com.boot.common.result.Result;
import com.boot.system.service.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/role")
public class RoleController {

    private final RoleService roleService;

    @AnnoLog(value = "角色新增")
    @RepeatSubmit
    @PostMapping("/add")
    public Result<?> addRole(@RequestBody Map<String, Object> dataParam) {
        return roleService.addRole(dataParam);
    }

    @AnnoLog(value = "角色修改")
    @RepeatSubmit
    @PostMapping("/update")
    public Result<?> updateRole(@RequestBody Map<String, Object> dataParam) {
        return roleService.updateRole(dataParam);
    }

    @AnnoLog(value = "角色删除")
    @RepeatSubmit
    @PostMapping("/delete")
    public Result<?> deleteRole(@RequestBody Map<String, Object> dataParam) {
        return Result.success(roleService.deleteRole((String) dataParam.get("ids")));
    }

    @AnnoLog(value = "角色查询")
    @PostMapping("/list")
    public Result<?> roleList(@RequestBody Map<String, Object> queryParam) {
        return Result.success(roleService.getRolePage(queryParam));
    }

    @AnnoLog(value = "角色列表")
    @GetMapping("/getList")
    public Result<?> getRoleList() {
        return Result.success(roleService.getRoleList());
    }

}
